<?php
header("Access-Control-Allow-Origin:*");
/*
http://学生所在节点IP/openapi/om_html5/upload_file.php
参数:
filedata //文件域名称
cid //课时名称
uid //学生编号
*/
$return = 2;
$cid  = isset($_REQUEST['cid']) ? $_REQUEST['cid']:'';
$uid  = isset($_REQUEST['uid']) ? $_REQUEST['uid']:'';
if($cid && $uid && $_FILES["filedata"]["size"] < 10485760){
    if ($_FILES["filedata"]["error"] == 0) {
		$file_root = dirname(dirname(dirname(__FILE__))).'/data/attachment/om_html5/';
		$file_path = $file_root.'/'.$cid.'/';
		$file_name = $uid.'-'.$_FILES["filedata"]["name"];
		$file_path_filename = $file_path.$file_name;
		if (!is_dir($file_root)) {
			mkdir($file_root, 0777);
		}
		if (!is_dir($file_path)) {
			mkdir($file_path, 0777);
		}
        @move_uploaded_file($_FILES["filedata"]["tmp_name"], $file_path_filename);
		@file_put_contents($file_path.'file_'.$_SERVER['HTTP_HOST'].'.log',$cid.'_'.$uid.'_'.$file_name.'_'.date('Y-m-d H:i:s',time()).PHP_EOL,FILE_APPEND);
		if(file_exists($file_path_filename) && filesize($file_path_filename) > 1){
			$return = 1;
		}
	}
}
echo $return;